<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>兑换金币</title>
    <link rel="stylesheet"  href="src/css/base.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/pages.css?__version=9.4">
    <script type="text/javascript" src="src/js/jquery-1.10.1.min.js?__version=9.4"></script>
    <script type="text/javascript" src="src/js/rem.js?__version=9.4"></script>
    <script type="text/javascript" src="src/js/dropload.js?__version=9.4"></script>
    <script type="text/javascript" src="src/js/init.js?__version=9.4"></script>

	<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script src="/src/js/share.js?__version=9.4"></script>
	<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ed2efe5b24e14f351f4d88ba2eb3462";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
</head>
<body>
	<div class="init_content" style="display: none;">
    <div class="warp changeCoins-warp">
        <section class="caption" id="htmlDataList">
            
        </section>

        <button type="button" class="btn btn-yellow" id="button" onclick="exchange()"></button>
    </div>
	</div>
    <div class="init_loading">
        <img src="src/img/page_loading.gif?v=1">
    </div>
</body>
<script>
addheader("兑换金币","javascript:history.back(-1);");
$(function (){
	var toys = cookieGet('toys');
	toys = JSON.parse( toys );
	
	var htmlDataList = "";
	var moneyAll = 0;
	for(var i = 0;i<toys.length;i++){
		moneyAll = Number(moneyAll)+Number(toys[i].money);
		htmlDataList += '<label class="item flex">';
		htmlDataList += '<img src="'+toys[i].img+'" width="50px;" heoght="50px;">';
		htmlDataList += '<div class="info">';
		htmlDataList += '<p class="name text-beyond">'+toys[i].name+'</p>';
		htmlDataList += '<p class="num text-beyond">x'+toys[i].num+'</p>';
		htmlDataList += '</div>';
		htmlDataList += '<span class="align-right ">';
		htmlDataList += '<img class="icon-balance" src="src/img/chongbianniu.png">';
		htmlDataList += '<span>'+toys[i].money+'</span>';
		htmlDataList += '</span>';
		htmlDataList += '</label>';
	}
	$("#button").append('兑换金币(共'+moneyAll+')');
	$("#htmlDataList").append(htmlDataList);
})

function exchange(){
	var back_ids = cookieGet('back_ids');
	back_ids = JSON.parse(back_ids);
	console.log(back_ids);
	$.ajax({
		type:'post',
		url:api_url+'/OpenAPI/V1/User/backpackExchange',
		data:{toy_ids:back_ids,token:token},
		jsonp: 'callback',//跨域问题
		dataType:'jsonp',//跨域接收数据
		success:function (data){
			if(data.code == 0){
				alert('兑换成功');
				window.location.href='/personal.html';
			}else{
				alert('兑换失败');
				return;
			}
				
		},
		error:function (){
			alert('网络错误');
			return;
		}
	});
}

</script>
</html>